package com.zxjbyte.yiyi.module.upms.controller.user;

import com.zxjbyte.yiyi.framework.common.domain.api.PageResult;
import com.zxjbyte.yiyi.framework.common.domain.api.R;
import com.zxjbyte.yiyi.module.upms.domain.param.UserAddParam;
import com.zxjbyte.yiyi.module.upms.domain.param.UserListParam;
import com.zxjbyte.yiyi.module.upms.domain.param.UserUpdateParam;
import com.zxjbyte.yiyi.module.upms.domain.vo.UserDetailVO;
import com.zxjbyte.yiyi.module.upms.domain.vo.UserListVO;
import com.zxjbyte.yiyi.module.upms.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Author zhangxingjia
 * @Date 2024/9/9 14:01
 * @Version: 1.0
 */
@Slf4j
@Tag(name = "用户管理接口")
@RestController
@RequestMapping(value = "/upms/user")
public class UserController {

    @Resource
    private UserService userService;

    @Operation(summary = "用户列表")
    @GetMapping("/list")
    public PageResult<UserListVO> list(UserListParam param){
        return userService.list(param);
    }
    @Operation(summary = "用户详情")
    @GetMapping("/detail")
    public R<UserDetailVO> detail(@RequestParam Long id){
        UserDetailVO vo = userService.detail(id);
        return R.data(vo);
    }

    @Operation(summary = "新增用户")
    @PostMapping("/add")
    public R<?> add(@Valid @RequestBody UserAddParam param){
        userService.addUser(param);
        return R.ok();
    }

    @Operation(summary = "更新用户")
    @PostMapping("/update")
    public R<?> update(@Valid @RequestBody UserUpdateParam param){
        userService.updateUser(param);
        return R.ok();
    }

    @Operation(summary = "删除用户")
    @DeleteMapping("/delete")
    public R<?> delete(@RequestParam Long id){
        userService.deleteUser(id);
        return R.ok();
    }
}
